class Solution {
public:
    int largestSumAfterKNegations(vector<int>& nums, int k) {
        auto cmp=[](int& a,int& b){ return a>b;};
        priority_queue<int,vector<int>,decltype(cmp)> p(cmp);
        for (int num : nums) 
        {
            p.push(num);
        }
        for(int i=0;i<k;++i)
        {
                int x=p.top();
                p.pop();
                p.push(-x);
        }
        int ret=0;
        while(!p.empty())
        {
            ret+=p.top();
            p.pop();
        }
        return ret;
    }
};
